﻿#region Copyright(C) 2018 FI Ltd. All rights reserved.
// ==================================================================================================
// Copyright(C) 2018 FI Ltd. All rights reserved.
//
// SYSTEM NAME	    : FI.Net Application Framework
// COMPONENT ID	    : FI.Core
// COMPONENT DESC   : FI.Net Core Foundation
//
// CREATED DATE/BY  : 18 Aug 2018 / Tian Mi
//
// REVISION HISTORY :	
// DATE/BY			SR#/CS/PM#/OTHERS		DESCRIPTION OF CHANGE
// ==================================================================================================
#endregion

using System;
using System.ComponentModel;
using System.Configuration;
using System.Xml;

namespace FI.Core.Configuration
{
    /// <summary>
    /// A <see cref="ConfigurationElement"/> with two properties: name and type.
    /// </summary>
    public class NameTypeConfigurationElement: ConfigurationElement
    {
        #region Constants
        private const string NameProperty = "name";
        internal const string TypeProperty = "type";
        #endregion

        #region Properties
        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        /// <value>
        /// The name.
        /// </value>
        [ConfigurationProperty(NameProperty, IsRequired = true)]
        public string Name
        {
            get { return (string)base[NameProperty]; }
            set { base[NameProperty] = value; }
        }

        /// <summary>
        /// Gets or sets the type.
        /// </summary>
        /// <value>
        /// The type.
        /// </value>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods"), TypeConverter(typeof(AssemblyQualifiedTypeNameConfigurationConverter))]
        [ConfigurationProperty(TypeProperty, IsRequired = true)]
        public Type Type
        {
            get { return (Type)base[TypeProperty]; }
            set { base[TypeProperty] = value; }
        }
        #endregion

        #region Internal Methods
        /// <summary>
        /// Deserializes the specified reader.
        /// </summary>
        /// <param name="reader">The reader.</param>
        internal void Deserialize(XmlReader reader)
        {
            base.DeserializeElement(reader, false);
        }
        #endregion
    }
}
